﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Bll;
using AspNetCs.Common;
using AspNetCs.Enumerations;
using AspNetCs.Config;


public partial class Master_Admin_ManageAgent : Admin_BasePage
{
    protected int totalCount = 0;
    private int pageSize = 20;
    protected City city = new City();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if(!IsPostBack)
        {
            DataBindRepeater1();
        }
    }

    public string GetNetMuTypeName(string id)
    {
        string str = "";
        try
        {
            int NetMuType = StringHelper.isNumber_int(id);
            if (NetMuType > -1)
            {
                NetMuTypeEnum NetMu = (NetMuTypeEnum)NetMuType;
                str = NetMu.ToString();
            }
        }
        catch (Exception ex)
        {
            str = ex.Message;
            CustomException cus = new CustomException(ex);
        }
        return str;

    }

    public void DataBindRepeater1()
    {
        AspNetPager1.PageSize = pageSize;
        string cmdText="select *from Agent order by id desc";
        DataPagesOperate ope = new DataPagesOperate();
        ope.BindRepeater(cmdText, AspNetPager1, "id desc", "id", Repeater1, out totalCount);
    }


    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        LinkButton btn_modify = e.Item.FindControl("btn_modify") as LinkButton;
        LinkButton lbtnCheck = e.Item.FindControl("lbtnCheck") as LinkButton;
        LinkButton lbtnLock = e.Item.FindControl("lbtnLock") as LinkButton;
        LinkButton btn_del = e.Item.FindControl("btn_del") as LinkButton;
        int id = StringHelper.isNumber_int(e.CommandArgument);
        string cmdText = "delete from Agent where id={0} delete from PartSiteConfig where Province={1} and City={2}";
        if (e.CommandName == "delete")
        {
            HiddenField hldProvince = e.Item.FindControl("hldProvince") as HiddenField;
            HiddenField hldCity = e.Item.FindControl("hldCity") as HiddenField;
            cmdText = string.Format(cmdText,id,hldProvince.Value,hldCity.Value);
            ExcuteSqlTextBLL.ExcuteResult(cmdText);
        }
        else if (e.CommandName == "Modify")
        {
            Response.Redirect("Admin_AddAgent.aspx?id="+id);
        }
        else if (e.CommandName == "check")
        {
            int IsCheck = 0;
            if (lbtnCheck.Text == "审核")
            {
                IsCheck = 1;
            }
            cmdText = "update Agent set IsCheck={0} where id={1}";
            cmdText=string.Format(cmdText,IsCheck,id);
            ExcuteSqlTextBLL.ExcuteResult(cmdText);
        }
        else if (e.CommandName == "lock")
        {
            int IsLock = 0;
            if (lbtnLock.Text == "锁定")
            {
                IsLock = 1;
            }
            cmdText = "update Agent set IsLock={0} where id={1}";
            cmdText = string.Format(cmdText, IsLock, id);
            ExcuteSqlTextBLL.ExcuteResult(cmdText);
        }
        DataBindRepeater1();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        DataBindRepeater1();
    }
}
